<?php
	function my_admin_scripts(){
		wp_enqueue_script('adminjs', get_bloginfo("template_url").'/js/admin.js');
		wp_enqueue_script('mn', get_bloginfo("template_url").'/js/colorPicker.js');
		wp_enqueue_script('media-upload');
		wp_enqueue_script('jquery-ui-sortable');
		wp_enqueue_script('thickbox');
	}
	
	function my_admin_styles(){
		wp_enqueue_style('thickbox');
		wp_enqueue_style('global');
		wp_enqueue_style('wp-admin');
		wp_enqueue_style('fade_slider_css', get_bloginfo('template_url').'/css/admin.css');
		wp_enqueue_style('style', get_bloginfo("template_url").'/css/colorPicker.css');
	}
	
	add_action('admin_print_styles', 'my_admin_styles');
	add_action('admin_print_scripts', 'my_admin_scripts');

	include_once( TEMPLATEPATH."/framework/options/option_pagenavi.php");
	include_once( TEMPLATEPATH."/framework/options/option_dynamic_vars.php");
	include_once( TEMPLATEPATH."/framework/options/option_shortcodes.php");
	include_once( TEMPLATEPATH."/framework/options/option_metabox.php");

	$footer_sidebars = array('Footer Widget Left', 'Footer Widget Right', 'Footer Widget Center-Top');
	
	foreach($footer_sidebars as $rsidebar) {
		register_sidebar(array(
			'name'=> $rsidebar, 
			'description' => 'Custom Widgets', 
			'before_widget' => '<div class="footer_widget_firstly">', 
			'after_widget' => '</div>', 
			'before_title' => '<h3>', 
			'after_title' => '</h3>'
			));
	}
	
	
	$footer_bottom_sidebars = array('Footer Widget Bottom-Left', 'Footer Widget Bottom-Right');

	foreach($footer_bottom_sidebars as $psidebar) {
		register_sidebar(array(
			'name'=> $psidebar, 
			'description' => 'Custom Widgets', 
			'before_widget' => '<div class="footer_widget_center">', 
			'after_widget' => '</div>', 
			'before_title' => '<h3>', 
			'after_title' => '</h3>'
			));
	}

	
	$page_sidebars = array('Page Sidebars', 'Blog Sidebars', 'Simple Sidebars', 'All Pages Sidebar');
	
	foreach($page_sidebars as $pagesidebar) {
		register_sidebar(array(
			'name'=> $pagesidebar, 
			'description' => 'Custom Widgets', 
			'before_widget' => '<div class="page_sidebar_warp">', 
			'after_widget' => '</div>', 
			'before_title' => '<h3>', 
			'after_title' => '</h3>'
			));
	}

	
	add_action('admin_menu', 'framework_create_menu');
	
	function framework_create_menu() {

		add_menu_page('OverALL Settings', 'General Settings', 'administrator', 'framework', 'option_general_settings');
		add_submenu_page('framework', 'Fade Slider', 'Fade Slider', 'administrator','option_fade_slider', 'option_fade_slider');
		add_submenu_page('framework', 'Nivo Slider', 'Nivo Slider', 'administrator', 'option_nivo_slider', 'option_nivo_slider');
		add_submenu_page('framework', '3D Slider', '3D Slider', 'administrator', "option_3d_slider", 'option_3d_slider');
		add_submenu_page('framework', 'News & Headlines', 'News & Headlines', 'administrator', "option_headlines", 'option_headlines');
		add_submenu_page('framework', 'Home Intro Text', 'Home Intro Text', 'administrator', "option_intro_text", 'option_intro_text');
		add_submenu_page('framework', 'Home Widgets', 'Home Widgets', 'administrator', "option_home_widgets", 'option_home_widgets');
		add_submenu_page('framework', 'Contact Page', 'Contact Page', 'administrator', "option_contact", 'option_contact');
		add_submenu_page('framework', 'Footer Widgets', 'Footer Widgets', 'administrator', "option_footer_widgets", 'option_footer_widgets');
		add_submenu_page('framework', 'Footer Copyright', 'Footer Copyright', 'administrator', "option_footer_copyright", 'option_footer_copyright');
		add_submenu_page('framework', 'OverALL Others', 'OverALL Others', 'administrator', "option_others", 'option_others');

	}
		
	function option_others(){
		include_once( TEMPLATEPATH."/framework/options/option_others.php");
	}	
	
	function option_contact(){
		include_once( TEMPLATEPATH."/framework/options/option_contact.php");
	}	
	
	function option_footer_copyright(){
		include_once( TEMPLATEPATH."/framework/options/option_footer_copyright.php");
	}
		
	function option_footer_widgets(){
		include_once( TEMPLATEPATH."/framework/options/option_footer_widgets.php");
	}
	
	function option_home_widgets(){
		include_once( TEMPLATEPATH."/framework/options/option_home_widgets.php");
	}
	
	function option_intro_text(){
		include_once( TEMPLATEPATH."/framework/options/option_intro_text.php");
	}
	
	function option_headlines(){
		include_once( TEMPLATEPATH."/framework/options/option_headlines.php");
	}

	function option_general_settings(){
		include_once( TEMPLATEPATH."/framework/options/option_general_settings.php");
	}
	
	function option_fade_slider(){
		include_once( TEMPLATEPATH."/framework/options/option_fade_slider.php");
	}
	
	function option_nivo_slider(){
		include_once( TEMPLATEPATH."/framework/options/option_nivo_slider.php");
	}

	function option_3d_slider(){
		include_once( TEMPLATEPATH."/framework/options/option_3d_slider.php");
	}
	
	function fade_slider(){
		include_once( TEMPLATEPATH."/framework/options/fade_slider.php");
	}

	if (function_exists('register_nav_menus')){
		register_nav_menus( array(
			'primary' => __( 'Primary Navigation', 'twentyten' ),
		) );
	}
	
	function twentyten_page_menu_args( $args ) {
		if (get_option("disable_home_page", "on") == "on"){
			$args['show_home'] = true;
		}else{
			$args['show_home'] = false;
		}
		
		$args['container'] = false;
		return $args;
	}
	
	function remove_menu_title( $args ) {
		$args = preg_replace('/title=\"(.*?)\"/','',$args);
		return $args;
	}
	
	function change_menu_home( $args ) {
		$home_name = get_option('home_page_name', 'Home');
		$args = str_replace('Home', $home_name, $args);
		
		if (preg_match_all('/page-item-([0-9]+)/i', $args, $preg_match, PREG_SET_ORDER)) {
			foreach ($preg_match as $preg_content) {
			
				if(get_post_meta($preg_content[1], 'do_filter', true)){
					$args = str_ireplace("page-item-".$preg_content[1], "dohidden", $args);
				}
			}
		}
		
		return $args;
	}

	add_filter( 'wp_page_menu', 'remove_menu_title' );
	add_filter( 'wp_page_menu', 'change_menu_home' );
	
	add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
	



	function list_categories($name, $value, $startext, $cssid=null)
	{
		echo "<select id=\"$cssid\" name=$name>";
		echo "<option value=\"\">$startext</option>";
	
		$categories = get_categories("title_li=&orderby=name");
		foreach ($categories as $category)
		{
			$selected = ($value == $category->term_id) ? "selected=\"selected\"" : "";
			echo "<option $selected value='". $category->term_id ."'>". $category->name. "(" . $category->category_count . ")" ."</option>";
		}
		echo "</select>";

	}
	
	
	function list_pages($name, $value, $startext)
	{
		echo "<select name=$name>";
		echo "<option value=\"\">$startext</option>";
	
		$pages = get_pages(); 

		foreach ($pages as $page)
		{
			$selected = ($value == $page->ID) ? "selected=\"selected\"" : "";
			echo "<option $selected value='". $page->ID ."'>". $page->post_title ."</option>";
		}
		echo "</select>";
	}
	
	
	function list_onoff($name, $value)
	{
	
			echo "<select name='$name'>";
							$items = array('on', 'off');
							foreach ($items as $item)
							{
								$selected = ($value == $item) ? "selected=\"selected\"" : "";
								echo "<option $selected value='". $item ."'>". $item ."</option>";
							}
							echo "</select>";
							
	}


	
	function create_list($name, $value, $items)
	{
		echo "<select name='$name'>";
			foreach ($items as $item)
			{
				$selected = ($value == $item) ? "selected=\"selected\"" : "";
				echo "<option $selected value='". $item ."'>". $item ."</option>";
			}
		echo "</select>";
	}
	
	
	function quick_list($name, $value, $items, $cssid)
	{
		echo "<select id=\"$cssid\" name=\"$name\">";
			foreach ($items as $item)
			{
				$selected = ($value == $item) ? "selected=\"selected\"" : "";
				echo "<option $selected value='". $item ."'>". $item ."</option>";
			}
		echo "</select>";
	}
	
	
	
	
	
function noNavTitle( $content ) {
	$content = preg_replace('/title=\"(.*?)\"/','',$content);
	return $content;
}
add_filter( 'wp_list_pages', 'noNavTitle' );
	
	
	

function create_filter($this_page) {

	global $post; $thispage = $post->ID;
	$pagekids = get_pages("child_of=".$thispage."&sort_column=menu_order");
	if ($pagekids) {
		echo '<li class="current_page_item"><a href="'.  get_page_link($this_page->ID) .'"><span>'.get_option('first_filter', 'ALL').'</span></a></li>';
		wp_list_pages("depth=1&title_li=&sort_column=menu_order&sort_order=ASC&link_before=<span>&link_after=</span>&child_of=".$thispage);
	}else{
		echo '<li><a href="'.  get_page_link($this_page->post_parent) .'"><span>'.get_option('first_filter', 'ALL').'</span></a></li>';
		wp_list_pages('depth=1&title_li=&child_of='.$post->post_parent.'&sort_column=menu_order&sort_order=ASC&link_before=<span>&link_after=</span>');
	}

}
	
	
	
	
	
	
	


			
function create_page($this_page) {


	if( !$this_page->post_parent ) {
		
		
		$pagelist = '<li class="current_page_item"><a href="'.  get_page_link($this_page->ID) .'"><span>' . $this_page->post_title . '</span></a>';
		$children = wp_list_pages('sort_column=menu_order&sort_order=ASC&link_before=<span>&link_after=</span>&title_li=&child_of='.$this_page->ID.'&echo=0');
		if( $children ) $pagelist .= '<ul class="children">' . $children . '</ul>';
		$pagelist .= '</li>';
	}
	elseif( $this_page->ancestors ) {

		$ancestor = end($this_page->ancestors);
		$pagelist = wp_list_pages('sort_column=menu_order&sort_order=ASC&link_before=<span>&link_after=</span>&title_li=&include='.$ancestor.'&echo=0');
		$pagelist = str_replace('</li>', '', $pagelist);
		$pagelist .= '<ul class="children">' . wp_list_pages('sort_column=menu_order&sort_order=ASC&link_before=<span>&link_after=</span>&title_li=&child_of='.$ancestor.'&echo=0') .'</ul></li>';
	}
	return $pagelist;
}








/*

if ( ! function_exists( 'twentyten_posted_on' ) ) :

function twentyten_posted_on() {
	printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
		'meta-prep meta-prep-author',
		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
			get_permalink(),
			esc_attr( get_the_time() ),
			get_the_date()
		),
		sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
			get_author_posts_url( get_the_author_meta( 'ID' ) ),
			sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
			get_the_author()
		)
	);
}
endif;

if ( ! function_exists( 'twentyten_posted_in' ) ) :

function twentyten_posted_in() {
	// Retrieves tag list of current post, separated by commas.
	$tag_list = get_the_tag_list( '', ', ' );
	if ( $tag_list ) {
		$posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
	} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
		$posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
	} else {
		$posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
	}
	// Prints the string, replacing the placeholders.
	printf(
		$posted_in,
		get_the_category_list( ', ' ),
		$tag_list,
		get_permalink(),
		the_title_attribute( 'echo=0' )
	);
}
endif;

*/



// Custom callback to list comments in the your-theme style
function custom_comments($comment, $args, $depth) {
  $GLOBALS['comment'] = $comment;
 $GLOBALS['comment_depth'] = $depth;
  ?>
	<li id="li-comment-<?php comment_ID(); ?>" <?php comment_class() ?>>
   
		<div class="comment_container <?php
if (1 == $comment->user_id)
$oddcomment = "authcomment";
echo $oddcomment;
?>" id="comment-<?php comment_ID(); ?>">
			<div class="comment_author vcard"><?php commenter_link() ?>			 
</div>
			<div class="comment-meta"><?php edit_comment_link(__('Edit', 'overall'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
			<div class="comment_content">
			 <h3><?php echo get_comment_author_link(); ?></h3> 
			 <!-- say:<br /><br /> -->
 		
				<?php comment_text() ?>
				<?php if ($comment->comment_approved == '0') _e("\t\t\t\t\t<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'overall') ?>

			</div>
			
			
				<?php 
				if($args['type'] == 'all' || get_comment_type() == 'comment') :
				comment_reply_link(array_merge($args, array(
				 'reply_text' => __('Reply','overall'),
				 'login_text' => __('Log in to reply.','overall'),
				 'depth' => $depth,
				 'max_depth' => $args['max_depth'],				 
				 'before' => '<div class="comment_reply_link">',
				 'after' => '</div>'
				)));
			   endif;
		  ?>
			
		</div>
<?php } // end custom_comments


// Produces an avatar image with the hCard-compliant photo class
function commenter_link() {
 $commenter = get_comment_author_link();
 if ( ereg( '<a[^>]* class=[^>]+>', $commenter ) ) {
  $commenter = ereg_replace( '(<a[^>]* class=[\'"]?)', '\\1url ' , $commenter );
 } else {
  $commenter = ereg_replace( '(<a )/', '\\1class="url "' , $commenter );
 }
 $avatar_email = get_comment_author_email();
 $avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( $avatar_email, 80 ) );
 echo $avatar . "<br /><div style=\"text-align:center; font-size:11px;\">" .get_comment_date('M j, Y'). "<br />" .get_comment_date('g:i a')."</div>";
} // end commenter_link


if(get_option("disable_wpautop", "off") == "on"){
	remove_filter('the_content', 'wpautop');
	remove_filter('the_content', 'wptexturize');
}






?>
